package com.example.code2022;

import com.example.algorithm.AList.ListNode;

/**
 * @author: dangwen
 * @createDate: 2022/4/25
 * 206. 反转链表
 * 给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
 */
public class P206 {
    public static void main(String[] args) {

    }

    public static ListNode test(ListNode head){
        ListNode pre = null;
        ListNode curr = head;
        while (curr != null){
            ListNode next = curr.next;
            curr.next = pre;
            pre = curr;
            curr = next;
        }
        return pre;
    }

    public static ListNode test2(ListNode node){
        if (node == null || node.next == null){
            return node;
        }
        ListNode newHead = test2(node.next);
        node.next.next = node;
        node.next = null;
        return newHead;
    }

}
